<?php
class TTT_Myfilter_Block_Adminhtml_Sales_Grid extends Gold_Orderpreparation_Block_Adminhtml_Sales_Order_Grid
{
	protected $_entity = TTT_Myfilter_Model_Entity::ORDER;

	protected function _prepareLayout()
	{
		// Set Additional Save Current Filter Button
		$this->setChild('myfilter_button',
		$this->getLayout()->createBlock('adminhtml/widget_button')
				->setData(array(
						'id'		=>	'myfilter_button',
                    	'label'     =>  Mage::helper('adminhtml')->__('Save Current Filter As'),
                    	'onclick'   => 'askForSave()',
                    	'class'   	=> 'add'
                    ))
                    );
         // Adding JS Phtml file
         $this->setChild('filterjs',
         $this->getLayout()->createBlock('core/template')
        	 ->setTemplate('myfilter/filterjs.phtml')
         	->setSaveUrl($this->_getSaveFilterUrl())
         	->setGridBlock($this)
         	);
         return parent::_prepareLayout();
	}

	public function getSaveFilterButtonHtml()
	{
		return $this->getChildHtml('myfilter_button');
	}

	public function getFilterJsHtml()
	{
		return $this->getChildHtml('filterjs');
	}

	/**
	 * Adding the custom Button to the main buttons html
	 * Adding custom JS Also
	 * (non-PHPdoc)
	 * @see Mage_Adminhtml_Block_Widget_Grid::getMainButtonsHtml()
	 */
	public function getMainButtonsHtml()
	{
		$html = '';
		if($this->getFilterVisibility()){
			$html.= $this->getSaveFilterButtonHtml();
			$html.= $this->getFilterJsHtml();
			$html.= $this->getResetFilterButtonHtml();
			$html.= $this->getSearchButtonHtml();
		}
		return $html;
	}


	/**
	 * Creating a URL when the button is clicked
	 * @return URL to prepare save the current filter
	 */
	protected function _getSaveFilterUrl()
	{
		$filterVarName = $this->getVarNameFilter();
		$filterValue = $this->getRequest()->getParam($filterVarName, '');
		return Mage::helper("adminhtml")
			->getUrl("myfilter/adminhtml_index/saveajax/",
					array("entity" => $this->_entity)
			);
	}
}